Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word jets with word values #252

Merged

Conversation

uncomputable
Copy link
Collaborator

@uncomputable uncomputable commented Oct 12, 2024

Word jets can only host word values. Currently, our code has some assertions here and there that will fail at runtime if a non-word is passed. The assertions are not fully rigorous, especially regarding the maximum word type of TWO^(2^31).

This PR introduces the wrapper type Word which is guaranteed to be a valid word. Word is used everywhere where a word should be used.

This PR also optimized scribe to use as many word jets as possible. Fixes #155

Switch node::Inner::Word(Value) to node::Inner::Word(Word) and adapt all
code that touches word jets.
Replace recursive code with a loop over Value::iter_compact.
Optimize the `scribe` expression by using as many word jets as possible.
The resulting expression should smaller, faster and cheaper in fees.

We need the old, unoptimized `scribe` to generate Cmr::BITS. Expect for
that, I don't see any reason why anyone would use the unoptimized
`scribe`. To users shooting themselves in the foot, I redefine
`CoreConstructible::scribe` as the optimized variant.
@apoelstra
Copy link
Collaborator

Nice! Pretty slick that we can just use TMR comparisons like this to detect when values are words.

Later we may even want to "optimize" the TMR type into an enum where we special-case a few dozen common/special values, so we can compare just a couple bytes rather than 32.

Copy link
Collaborator

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK f4e259a successfully ran local tests

@apoelstra apoelstra merged commit 6af2c3e into BlockstreamResearch:master Oct 12, 2024
16 checks passed
@uncomputable uncomputable deleted the 2024-10-word-values branch October 12, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scribe with word jets
2 participants